package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import blogic.Operations;

import com.trip_memories.R;

import dbmodels.Photo;

public class MyPhotosArrayAdapter extends ArrayAdapter<Photo> {

	private final Context context;
	private final Photo[] values;
	//private final BusinessLogic bl;

	public MyPhotosArrayAdapter(Context context, Photo[] objects) {
		super(context, R.layout.album_view, objects);
		this.context = context;
		this.values = objects;
		//bl = AccesBussineLogic.getBussinesLogic(context);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.for_images, parent, false);
		ImageView image = (ImageView) rowView.findViewById(R.id.image);
		TextView imageName = (TextView) rowView.findViewById(R.id.image_name);
		image.setImageBitmap(Operations.convertFromBytesInBitmap(context, values[position].getBytes(), 0));
		imageName.setText(values[position].getName() + ".bmp");
		
		return rowView;
	}
}
